classdef OrderBookReader < handle
    properties (SetAccess = private)
        fileNameConst = 'orderBook';
        fileName = '';
        openOptions;
%         currentOrderBookCall;
%         currentOrderBookPut;
        currentOrderBook;
    end
    
    methods 
        %%
        function obj = OrderBookReader( osxOpenOptions )
            obj.openOptions = osxOpenOptions;
            obj.fileName = strcat( obj.fileNameConst, datestr(today), '.csv' );
            writeChangesToFile( obj.fileName, {datestr(now)}, 'w' );
%             [obj.currentOrderBookCall changes_c] = ...
%                 sampleOrderBookAsCell( osxOpenOptions.call_string, OptionMap( osxOpenOptions.call_string ) );
%             [obj.currentOrderBookPut changes_p] = ...
%                 sampleOrderBookAsCell( osxOpenOptions.put_string, OptionMap( osxOpenOptions.put_string ) );
%            writeChangesToFile( obj.fileName, changes_c, 'a' );
%            writeChangesToFile( obj.fileName,  changes_p, 'a' );
        
            tempStr = [osxOpenOptions.call_string osxOpenOptions.put_string];
           [obj.currentOrderBook changes] = ...
                sampleOrderBookAsCell( tempStr, OptionMap( tempStr ) );
           writeChangesToFile( obj.fileName, changes, 'a' );
        end
        
        
        %%
        function insertOrderBook( obj )
%             tic;
%            [obj.currentOrderBookCall, changes_c] = sampleOrderBookAsCell( obj.openOptions.call_string, obj.currentOrderBookCall );
%            [obj.currentOrderBookPut, changes_p] = sampleOrderBookAsCell( obj.openOptions.put_string, obj.currentOrderBookPut );
%            if ~isempty( changes_c )
%                 writeChangesToFile( obj.fileName, changes_c, 'a' );
%            end
%            if ~isempty( changes_p )
%                 writeChangesToFile( obj.fileName,  changes_p, 'a' );
%            end
%            toc
           
            tic;
           tempStr = [ obj.openOptions.call_string obj.openOptions.put_string];
           [obj.currentOrderBook, changes] = sampleOrderBookAsCell( tempStr, obj.currentOrderBook );
           if ~isempty( changes )
                writeChangesToFile( obj.fileName, changes, 'a' );
           end
           toc
        end
        
        
        %%
%         function writeChangesToFile( obj, changesString )
%             fid = fopen( obj.fileName, 'w');
%             fprintf(fid, changesString, y);
%             fclose(fid);
%         end
        
    end
end
    